package com.wsq.exoplayer2;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.ui.StyledPlayerControlView;
import com.google.android.exoplayer2.util.MimeTypes;

public class MainActivity extends AppCompatActivity {
    private PlayerView videoView;
    ExoPlayer player;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        player = new ExoPlayer.Builder(this, new FFmpegRenderersFactory(this)).build();
        videoView = findViewById(R.id.videoView);
        videoView.setPlayer(player);

    }

    @Override
    protected void onResume() {
        super.onResume();
        MediaItem item = MediaItem.fromUri("http://192.168.0.140:5678/downloads/new_h264.mov");
        MediaItem item1 = MediaItem.fromUri("http://192.168.0.140:5678/downloads/t1.mp4");
        item1 = new MediaItem.Builder().setUri("http://192.168.0.140:5678/downloads/t2.mp4")
                .setMimeType(MimeTypes.APPLICATION_MP4).build();
//        player.addMediaItem(item);

        player.addMediaItem(item);
        player.prepare();

//        player.add
        player.play();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        player.release();
    }
}